package com.gensdai.leliang.view.banner;

import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gensdai.leliang.R;
import com.gensdai.leliang.view.banner.widget.Banner.BaseIndicaorBanner;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 简单的banner
 */
public class SimpleImageBanner extends
        BaseIndicaorBanner<PageInfo, SimpleImageBanner> {
    private ColorDrawable colorDrawable;

    public SimpleImageBanner(Context context) {
        this(context, null, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        colorDrawable = new ColorDrawable(Color.parseColor("#555555"));
    }

    @Override
    public void onTitleSlect(TextView tv, int position) {
        final PageInfo item = list.get(position);
        tv.setText(item.getTitle());
    }

    @Override
    public View onCreateItemView(int position) {
        View inflate = View.inflate(context, R.layout.adapter_simple_image,
                null);
        SimpleDraweeView img = (SimpleDraweeView)inflate.findViewById(R.id.img);
        ImageView videoplaybtn = (ImageView)inflate.findViewById(R.id.videoplayBtn);

        final PageInfo item = list.get(position);
//		int itemWidth = dm.widthPixels;
//		int itemHeight = (int) (itemWidth * 360 * 1.0f / 640);
//		iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
//		iv.setLayoutParams(new LinearLayout.LayoutParams(itemWidth, itemHeight));

        String imgUrl = item.getImgPath();

        if (!TextUtils.isEmpty(imgUrl)) {
            img.setImageURI(Uri.parse(imgUrl));
        } else {
            img.setImageURI(Uri.parse(""));
        }

        if("video".equalsIgnoreCase(item.getType())){
            videoplaybtn.setVisibility(VISIBLE);
        }else{
            videoplaybtn.setVisibility(GONE);
        }

        return inflate;
    }
}